﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace EnterpriseLibraryExtensions.Events.Aggregation
{
    /// <summary>
    /// The NoFilteringOptions can be assigned as ScopeOptions to an EventAggregationScope when no filtering is desired.
    /// </summary>
    public struct NoFilteringOptions : IScopeOptions
    {
        /// <summary>
        /// Implements the operator ==.
        /// </summary>
        /// <param name="left">The left value to compare with the right. </param>
        /// <param name="right">The right value to commpare with the left.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator ==(NoFilteringOptions left, NoFilteringOptions right)
        {
            return left.Equals(right);
        }

        /// <summary>
        /// Implements the operator !=.
        /// </summary>
        /// <param name="left">The left value to compare with the right. </param>
        /// <param name="right">The right value to commpare with the left.</param>
        /// <returns>The result of the operator.</returns>
        public static bool operator !=(NoFilteringOptions left, NoFilteringOptions right)
        {
            return !(left == right);
        }

        /// <summary>
        /// Returns the enlistedEventHandlers without filtering them.
        /// </summary>
        /// <param name="enlistedEventHandlers">The enlisted eventhandlers to filter.</param>
        /// <returns>A readonly collection containing the same elements as was provided as input.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if enlistedEventHandlers is null.</exception>
        public ReadOnlyCollection<IEnlistedEventHandler> RemoveDuplicates(IEnumerable<IEnlistedEventHandler> enlistedEventHandlers)
        {
            if (enlistedEventHandlers == null)
            {
                throw new ArgumentNullException("enlistedEventHandlers");
            }

            var handlers = new List<IEnlistedEventHandler>(enlistedEventHandlers);
            
            return new ReadOnlyCollection<IEnlistedEventHandler>(handlers);
        }

        /// <summary>
        /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
        /// <returns>
        /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
        {
            return obj is NoFilteringOptions;
        }

        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. 
        /// </returns>
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        /// <summary>
        /// Returns a plain, readable string saying NoFilteringOptions.
        /// </summary>
        /// <returns>NoFilteringOptions</returns>
        public override string ToString()
        {
            return "NoFilteringOptions";
        }
    }
}
